//
//  XQIdentityJobController.m
//  JoinPeso
//
//  Created by 小琦 on 2024/11/26.
//

#import "XQIdentityJobController.h"

@interface XQIdentityJobController ()
@end

@implementation XQIdentityJobController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.startInterval = [XQTimeTool nowTimeStamp];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self startLocation];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self stopLocation];
}

- (void)refreshData {
    NSDictionary *dic = @{
        @"accommodate" : self.cardId
    };
    [XQHUD showLoadingInView:self.view];
    @weakify(self)
    [XQAFNetworking postWithUrl:[XQNetManager getAbsolutePath:@"/direct/provisionally"] pars:dic callback:^(_Bool success, id  _Nonnull responseObject, NSError * _Nonnull error) {
        @strongify(self);
        [XQHUD hideLoadindInView:self.view];
        if ([responseObject[@"concept"] integerValue] == 0) {
            NSDictionary *accomplish = responseObject[@"accomplish"];
            if ([accomplish[@"concluded"] isKindOfClass:[NSArray class]]) {
                self.dataSource = accomplish[@"concluded"];
                
                if (self.dataSource.count > 0) {
                    for (NSDictionary *dic in self.dataSource) {
                        NSString *key = dic[@"concept"];
                        NSString *value = dic[@"maneuvering"];
                        if (key.length) {
                            NSString *v = [self getChooseSpaceMobile:value dic:dic];
                            [self.dataDic setValue:v forKey:key];
                        }
                    }
                }
            }
            [self.tableView reloadData];
        }
    }];
}

- (void)clickNextButton {
    NSMutableDictionary *dic = @{
        @"accommodate" : self.cardId
    }.mutableCopy;
    
    if (self.dataDic.count > 0) {
        for (NSString *key in self.dataDic) {
            NSString *value = self.dataDic[key];
            [dic setValue:value forKey:key];
        }
    }
    
    [XQHUD showLoadingInView:self.view];
    @weakify(self)
    [XQAFNetworking postWithUrl:[XQNetManager getAbsolutePath:@"/direct/vet"] pars:dic callback:^(_Bool success, id  _Nonnull responseObject, NSError * _Nonnull error) {
        @strongify(self);
        [XQHUD hideLoadindInView:self.view];
        if ([responseObject[@"concept"] integerValue] == 0) {
            [self reportRisk];
            [self.navigationController popViewControllerAnimated:YES];
        }else {
            [XQToast showMsg:responseObject[@"loon"]];
        }
    }];
}

- (void)reportRisk {
    [XQGoogleMarket reportRiskWithType:@"6" longitude:self.longitude latitude:self.latitude startTime:self.startInterval endTime:[XQTimeTool nowTimeStamp] orderId:@""];
}

@end
